<!--  -->
<template>
  <div>
    <div v-if="requestError" class="text-c errorPlace">
      <img width="100px" height="100px" :src="require('@/assets/images/pic_neterror.png')" alt="获取数据失败" />
      <div class="color-b font14" style="margin: 10px 0 0 0">
        获取数据失败!
      </div>
      <van-button plain round size="small" color="#7232dd" type="primary" @click="getdetail">点击重试</van-button>
    </div>
    <van-form v-else @submit="submitFromData">

      <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
        <div class="blue_item" />
        <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">线索基本信息</span>
      </div>
      <van-field readonly required name="city" :value="fromdata.city" label="地市：" />
      <van-field readonly required name="county" :value="fromdata.county" label="县区：" />
      <van-field readonly required name="customerName" :value="fromdata.customerName" label="客户单位名称：" />
      <van-field readonly required name="clueCode" :value="fromdata.clueCode" label="线索编码：" />
      <van-field readonly required name="clueName" :value="fromdata.clueName" label="线索名称：" />
      <van-field readonly required name="projectStage" :value="fromdata.projectStage" label="项目阶段：" />
      <van-field readonly required autosize type="textarea" rows="1" name="projectDesc" :value="fromdata.projectDesc"
        label="商机简介：" />
      <van-field readonly required name="projectBudget" :value="fromdata.projectBudget" label="预算金额（万元）：" />
      <van-field readonly required name="data2" :value="fromdata.data2" label="是否招投标：" />
      <van-field readonly required name="currentSituation" :value="fromdata.currentSituation" label="当前形势：" />
      <van-field readonly required name="mgrName" :value="fromdata.mgrName" label="客户经理姓名：" />
      <van-field readonly required name="mgrBill" :value="fromdata.mgrBill" label="客户经理电话：" />
      <van-field readonly required name="mgrCode" :value="fromdata.mgrCode" label="客户经理工号：" />
      <van-field readonly required name="city" :value="fromdata.city" label="归属市单位：" />
      <van-field readonly required name="county" :value="fromdata.county" label="归属县单位：" />
      <van-field readonly required name="customerCode" :value="fromdata.customerCode" label="全网客户编码：" />
      <van-field readonly required name="groupId" :value="fromdata.groupId" label="省内客户编码：" />
      <van-field readonly required name="customerName" :value="fromdata.customerName" label="客户名称：" />
      <van-field readonly required name="regionId" :value="fromdata.regionId" label="客户等级：" />
      <van-field readonly required name="industryType" :value="fromdata.industryType" label="行业类型：" />
      <van-field readonly name="businessType" :value="fromdata.businessType" label="业务类型：" />
      <van-field readonly name="keyProject" :value="fromdata.keyProject" label="行业重点项目：" />
      <van-field readonly name="keyProjectType" :value="fromdata.keyProjectType" label="重点项目类型：" />
      <van-field readonly name="hotProjectType" :value="fromdata.hotProjectType" label="近期热点项目类型：" />
      <van-field readonly name="solutionType" :value="fromdata.solutionType" label="12项解决方案类型：" />
      <van-field readonly required name="isConverBusiness" :value="fromdata.isConverBusiness" label="是否转化成商机：" />
      <van-field readonly required autosize type="textarea" rows="1" name="notConverReason"
        :value="fromdata.notConverReason" label="不转化原因：" />

      <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
        <div class="blue_item" />
        <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">商机基本信息</span>
      </div>
      <van-field readonly required name="businessName" :value="fromdata.businessName" label="商机名称：" />
      <van-field readonly name="businessId" :value="fromdata.businessId" label="商机编号：" />
      <van-field readonly required name="busiOpportSource" :value="fromdata.busiOpportSource" label="商机来源：" />
      <van-field readonly required name="contactPerson" :value="fromdata.contactPerson" label="客户联系人：" />
      <van-field readonly required name="contactPersonPhone" :value="fromdata.contactPersonPhone" label="客户联系人电话：" />
      <van-field readonly required name="securityLevel" :value="fromdata.securityLevel" label="保密级别：" />

      <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
        <div class="blue_item" />
        <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">商机业务信息</span>
      </div>
      <van-field readonly required name="custRelationship" :value="fromdata.custRelationship" label="客情关系：" />
      <van-field readonly required name="preAmount" :value="fromdata.preAmount" label="预估金额（万元）：" />
      <van-field readonly required name="preAmountY" :value="fromdata.preAmountY" label="预估金额（元）：" />
      <van-field readonly required name="businessGrade" :value="fromdata.businessGrade" label="商机分级：" />
      <van-field readonly required name="projectUrgency" :value="fromdata.projectUrgency" label="项目紧急程度：" />
      <van-field readonly required name="businessStatus" :value="fromdata.businessStatus" label="商机状态：" />
      <van-field readonly required name="crossDomainType" :value="fromdata.crossDomainType" label="业务跨域类型：" />
      <van-field readonly name="involvedProducts" :value="fromdata.involvedProducts" label="涉及具体产品：" />
      <van-field readonly name="involvedSolutions" :value="fromdata.involvedSolutions" label="涉及具体解决方案：" />
      <van-field readonly name="fiveGSubdivisions" :value="fromdata.fiveGSubdivisions" label="涉及具体5G细分行业：" />

      <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
        <div class="blue_item" />
        <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">一级DICT行业信息</span>
      </div>
      <van-field readonly required name="industryName" :value="fromdata.industryName" label="9大行业名称：" />
      <van-field readonly required name="industryNameOneLevel" :value="fromdata.industryNameOneLevel" label="行业一级名称：" />
      <van-field readonly required name="industryNameTwoLevel" :value="fromdata.industryNameTwoLevel" label="行业二级名称：" />

      <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
        <div class="blue_item" />
        <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">外部合作伙伴支撑信息</span>
      </div>
      <van-field readonly required name="partnerSupportNeeds" :value="fromdata.partnerSupportNeeds" label="外部合作伙伴支撑需求：" />
      <van-field readonly required name="partnerName" :value="fromdata.partnerName" label="外部合作伙伴名称：" />

      <div class="mt10" style=" display: flex;border-bottom: 1px solid #ebedf0;">
        <div class="blue_item" />
        <span class="font15" style="display: flex; line-height: 33px;margin-left:5px;  flex:1;">商机评估信息</span>
      </div>
      <van-field readonly required name="businessValidityScore" :value="fromdata.businessValidityScore" label="评估得分：" />
      <van-field readonly required autosize type="textarea" rows="1" name="businessValidity"
        :value="fromdata.businessValidity" label="商机有效性评估：" />
      <van-field readonly required name="businessWorthScore" :value="fromdata.businessWorthScore" label="评估得分：" />
      <van-field readonly required autosize type="textarea" rows="1" name="businessWorth" :value="fromdata.businessWorth"
        label="商机价值评估：" />
      <van-field readonly required name="businessAbilityScore" :value="fromdata.businessAbilityScore" label="评估得分：" />
      <van-field readonly required autosize type="textarea" rows="1" name="businessAbility"
        :value="fromdata.businessAbility" label="商机转化能力评估：" />
      <van-field readonly required name="businessScreensTotal" :value="fromdata.businessScreensTotal" label="评估得分：" />
      <van-field readonly required name="businessAssess" :value="fromdata.businessAssess" label="商机参与度评估：" />
      <van-field readonly autosize type="textarea" rows="1" name="remark" :value="fromdata.remark" label="备注：" />
      <van-field readonly name="descriptionFileList" :value="fromdata.descriptionFileList" label="说明文件：" />


      <!-- 当前办理人和审批意见 -->
      <historyAndSuggs :showHistory='showHistory' :historydata='historydata' :approveList='approveList' />
      <!-- 流转下一步 -->
      <div v-if="todotype==true||toread==true" class="footer">
        <van-button block type="info" native-type="submit" :disabled="canToNext==true?false:true"
          style="display: inline-block;width:100%;border: 0px solid #60a9ec;">{{toNextValue}}</van-button>
      </div>
    </van-form>

  </div>
</template>

<script>
import { getFormDetail, getSrqrRequest, wfWorkItemModel, getWfOptMags } from '@/api/dictapi'
import util from "@/assets/js/public";
import tabone from "@/views/srqr/tabone"
import tabtwo from "@/views/srqr/tabtwo"
import tabthree from "@/views/srqr/tabthree"
import { mapGetters } from "vuex"
import { Notify, Dialog, Toast } from 'vant'
import moment from 'moment'

export default {
  data() {
    return {
      active: 0,
      requestError: false,
      params: this.$route.query,
      showHistory: false,
      historydata: {},//已办显示当前办理人
      fromdata: {},//收入确认信息
      fromdata2: {},//项目交底信息
      fromdata3: {},//合同交底信息
      contractList: [],//合同列表
      incomeList: [],//已交底合同信息列表
      billingList: [],//计费科目信息列表
      approveList: [],//审批意见列表
      canToNext: true,
      todotype:false,
      toread:false,
      toNextValue:'',
    }
  },
  computed: {
    ...mapGetters(['user']),
    ...mapGetters(['userinfo'])
  },
  //生命周期--创建完成
  created() {
    if (this.params.todoType % 2 == 0) {
      this.showHistory = true;
    }else if (this.params.todoType % 3 == 0) {
      this.toread = true;
    }else {
      this.todotype = true;
    }
    if(this.params.todoType=='1'){
      if(this.params.location=='dict.start'){
        this.canToNext=false
        this.toNextValue='暂不支持该环节,请至PC端办理'
      }else {
        this.canToNext=true
        this.toNextValue='流转下一步'
      }
    }
    this.getdetail();
  },
  //生命周期--挂载完成
  components: {
    tabone,
    tabtwo,
    tabthree
  },
  //方法调用
  methods: {
    goBack() {
      this.$router.back(-1) //返回上一页
    },
    onError(result) {
      this.requestError = true;
      Toast.clear();
      Notify(result.message);
    },
    getdetail() {
      Toast.loading({
        message: '加载中',
        forbidClick: false
      });

      getFormDetail(Object.assign(this.params, { userName: this.user.userName }))
        .then((result) => {
          if (!result.data) {
            this.onError(result);
            return;
          }
          if (result.data.data) {
            this.params.pmInsId = result.data.data.pmInsId;
            this.getIncomeAffirmByPmInsId();//收入确认页签信息
          }

        })
    },
    getIncomeAffirmByPmInsId() {
      getSrqrRequest('incomeAffirm$api$getIncomeAffirmByPmInsId',
        Object.assign(this.params, {
          kv: {
            "source": 'MOBILE',
            "pmInsId": this.params.pmInsId,
            "currentUserCode": util.encrypt(this.params.userName),
          }
        }
        ))
        .then((result) => {
          Toast.clear();
          if (!result.data) {
            this.onError(result);
            return;
          }
          if (result.data.data) {
            this.requestError = false;
            this.fromdata = result.data.data;
            this.billingList = this.fromdata.incomeListModel;

            this.params.projectID = this.fromdata.projectEstablishNumber
            this.params.projectId = this.fromdata.projectEstablishNumber
            this.params.projectEstablishNumber = this.fromdata.projectEstablishNumber

            // this.getProjectDelNewInformationByProjectNumber();//目前看没啥用
            this.getEsopBusinessToProjectByNumber();//项目页签信息
            this.getPaymentContractBlocAllByProjectId();//合同列表，每个页签都有
            this.getIncomContractListByNumber();
          }
          if (this.showHistory) {
            this.wfWorkItemModel();
          }
          this.getWfOptMags()
        })
    },
    // getProjectDelNewInformationByProjectNumber() {
    //   getSrqrRequest('projectInformation$api$getProjectDelNewInformationByProjectNumber',
    //     Object.assign(this.params, {
    //       kv: {
    //         "source": 'MOBILE',
    //         "projectID": this.params.projectID,
    //         "currentUserCode": util.encrypt(this.params.userName),
    //       }
    //     }
    //     )).then((result) => { })
    // },
    getEsopBusinessToProjectByNumber() {
      getSrqrRequest('esopBusinessToProject$api$getEsopBusinessToProjectByNumber',
        Object.assign(this.params, {
          kv: {
            "source": 'MOBILE',
            "projectEstablishNumber": this.params.projectEstablishNumber,
            "currentUserCode": util.encrypt(this.params.userName),
          }
        }
        )).then((result) => {
          if (result.data.data) {
            this.fromdata2 = result.data.data
          }
        })
    },
    getPaymentContractBlocAllByProjectId() {
      getSrqrRequest('contractWarehouseBloc$api$getPaymentContractBlocAllByProjectId',
        Object.assign(this.params, {
          kv: {
            "source": 'MOBILE',
            "projectId": this.params.projectId,
            "currentUserCode": util.encrypt(this.params.userName),
          }
        }
        )).then((result) => {
          if (result && result.data && result.data.data) {
            this.contractList = result.data.data
          }
        })
    },
    getIncomContractListByNumber() {
      getSrqrRequest('esopBusinessToProjectContract$api$getIncomContractListByNumber',
        Object.assign(this.params, {
          kv: {
            "source": 'MOBILE',
            "projectEstablishNumber": this.params.projectEstablishNumber,
            "currentUserCode": util.encrypt(this.params.userName),
          }
        }
        )).then((result) => {

          if (!result.data) {
            Notify(result.message);
            return;
          }
          if (result.data.data) {
            this.params.contractSerialNumber = result.data.data[0].contractSerialNumber
            this.params.contractPmInsId = result.data.data[0].pmInsId
            this.getContractSendBasicData();//合同页签信息
            this.getContractIncomeListAndEsopModel();//已交底合同信息
          }
        })
    },
    getContractSendBasicData() {
      getSrqrRequest('projectManage$api$getContractSendBasicData',
        Object.assign(this.params, {
          kv: {
            "source": 'MOBILE',
            "contractSerialNumber": this.params.contractSerialNumber,
            "currentUserCode": util.encrypt(this.params.userName),
          }
        }
        )).then((result) => {
          if (result.data.data) {
            this.fromdata3 = result.data.data
            this.fromdata3.PROJECT_NAME = this.fromdata.projectEstablishName
          }
        })
    },
    getContractIncomeListAndEsopModel() {
      getSrqrRequest('projectManage$api$getContractIncomeListAndEsopModel',
        Object.assign(this.params, {
          kv: {
            "source": 'MOBILE',
            "contractSerialNumber": this.params.contractSerialNumber,
            "pmInsId": this.params.contractPmInsId,
            "currentUserCode": util.encrypt(this.params.userName),
          }
        }
        )).then((result) => {
          this.incomeList = result.data.data
        })
    },
    wfWorkItemModel() {
      wfWorkItemModel(Object.assign(this.params, { userName: this.user.userName }))
        .then((result) => {
          if (!result.data) {
            Notify(result.message);
            return;
          }
          if (result.data.data) {
            this.historydata = result.data.data
          }
        })
    },

    getWfOptMags() {
      getWfOptMags(Object.assign(this.params), { userName: this.user.userName })
        .then((result) => {
          if (!result.data) {
            Notify(result.message);
            return;
          }
          this.approveList = result.data.data.reverse();
        })
    },

    submitFromData() { //提交流转
      this.params.formData = this.fromdata;
      this.params.pmInsType = 'SRQR2'
      console.log("传给递交页面:", this.params)
      var params1 = {
        kv: {
          currentUserCode: util.encrypt(this.params.userName),
          source: 'MOBILE',
          location: this.params.location,
          processInstId: this.params.processInstId,
          processDefName: this.params.processDefName,
          processType: 'SRQR2',
        },
      };
      var params2 = {
        kv: {
          "currentUserCode": util.encrypt(this.params.userName),
          "source": 'MOBILE',
          "location": this.params.location,
          "processInstId": this.params.processInstId,
          'processType': 'SRQR2',
          'receiptCode': this.params.processInstId
        },
      };
      var params3 = {
        kv: {
          "source": 'MOBILE',
          "currentUserCode": util.encrypt(this.params.userName),
          "workItemId": this.params.workItemId,
          "processInstId": this.params.processInstId,
          "location": this.params.location,
        },
      };
      localStorage.setItem('submitPageParam', JSON.stringify({
        getDecisionsUrl: 'decisionAndUser$api$getDecisions',
            getDecisionsParams: params1,
            getUserUrl: 'decisionAndUser$api$getOrgAndUser',
            getUserParams: params2,
            tosubmintUrl: 'decisionAndUser$api$startSubmitProcess',
            tosubmintParams: params3,
            fromMoa:this.params.fromMoa
          }));
      this.$router.push(
        {
          name: 'srqrsubmit'
        }
      );
      // this.$router.push(
      //   {
      //     name: 'srqrsubmit',
      //     params: this.params
      //   }
      // );
    },

  }
}
</script>
<style  scoped>
.errorPlace {
  position: absolute;
  margin-top: -80px;
  top: 50%;
  margin-left: -50px;
  left: 50%;
}</style>